// pages/partner/setManage/setManage.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    switch_value: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getSwitchConfig();
  },


  //获取积分开关配置
  getSwitchConfig() {
    var that = this;
    // ajax请求
    app.ajax({
      url: 'Partner/Achievement/getIntegralSetting',
      data: {},
      success: function (res) {
        if (res.data.code == 1000) {
          that.setData({
            switch_value: res.data.data.integral_setting == 1 ? true : false
          })
        }
      }
    })
  },
  switchChange(e) {
    console.log(e)
    var that = this;
    // ajax请求
    app.ajax({
      url: 'Partner/Achievement/integralSetting',
      data: {
        set_value: e.detail.value ? '1' : '2',
      },
      success: function (res) {
        app.showToast(res.data.message);
        if (res.data.code == 1000) {
          const eventChannel = that.getOpenerEventChannel();
          eventChannel.on('acceptDataFromOpenerWaterRecharge', function (data) {
            eventChannel.emit('acceptDataFromOpenedMange', {});
          })
          that.getSwitchConfig();
        }
      }
    })
  }
})